Handling of gpsbabel process and named pipe changed.
authoroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 8 Nov 2005 00:17:22 +0000 (00:17 +0000)
committeroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 8 Nov 2005 00:17:22 +0000 (00:17 +0000)
gpsbabel/win32/gui-2/utils.pas

index c3f0c9a25fab28db1b5800526531590081640b4a..f9e44cbce7e4ed39d7fc838e5293f81037c8157c 100644 (file)
@@ -46,6 +46,7 @@ procedure FixStaticText(AComponent: TComponent);
 implementation\r
 \r
 uses\r
+  Forms,\r
   StdCtrls,\r
   common;\r
 \r
@@ -70,6 +71,7 @@ var
   BytesRead, BytesDone: DWORD;\r
   buffer: packed array[0..512] of Char;\r
   Error: DWORD;\r
+  Wait_Result: DWORD;\r
   s: string;\r
 \r
 begin\r
@@ -109,24 +111,28 @@ begin
       raise eGPSBabelError.CreateFmt(\r
         _('Could not run "gpsbabel.exe" (Error %d)!'), [Error]);\r
     end;\r
-    while (WaitforSingleObject (ProcessInfo.hProcess, 0)) <> WAIT_OBJECT_0 do sleep(100);\r
-    if not GetExitCodeProcess(ProcessInfo.hProcess, Error) then Error := 0;\r
-\r
-    if (Error <> 0) and (Error <> 1) then\r
-      raise eGPSBabelError.CreateFmt(_('"gpsbabel.exe" returned error 0x%x (%d)'), [Error, Error]);\r
 \r
     s := '';\r
 \r
-    PeekNamedPipe(hRead, nil, 0, nil, @BytesRead, nil);\r
+    repeat\r
+      Wait_Result := WaitforSingleObject(ProcessInfo.hProcess, 50);\r
+      if PeekNamedPipe(hRead, nil, 0, nil, @BytesRead, nil) then\r
+      begin\r
+        Application.ProcessMessages;\r
+        while (BytesRead > 0) do\r
+        begin\r
+          ReadFile(hRead, Buffer, SizeOf(buffer)-1, BytesDone, nil);\r
+          buffer[BytesDone] := #0;\r
+          s := s + string(buffer);\r
+          Dec(BytesRead, BytesDone);\r
+        end;\r
+      end;\r
+    until (Wait_Result = WAIT_OBJECT_0);\r
 \r
-    while (BytesRead > 0) do\r
-    begin\r
-      ReadFile(hRead, Buffer, SizeOf(buffer)-1, BytesDone, nil);\r
-      buffer[BytesDone] := #0;\r
-      s := s + string(buffer);\r
+    if not GetExitCodeProcess(ProcessInfo.hProcess, Error) then Error := 0;\r
 \r
-      Dec(BytesRead, BytesDone);\r
-    end;\r
+    if (Error <> 0) and (Error <> 1) then\r
+      raise eGPSBabelError.CreateFmt(_('"gpsbabel.exe" returned error 0x%x (%d)'), [Error, Error]);\r
 \r
     Output.Clear;\r
     Output.SetText(PChar(s));\r